﻿@{
    Layout = null;
}
@using Kevin.Shop.Business.Service.Entity.Helper
@model RiderShop.Mobile.Modle.MyAccount.MyPromotionCodeModel

<!doctype html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
    <title>领取优惠券</title>
    <!-- Bellows Styles -->
    <link href="~/Themes/RongJi/Style/luckybag/css/style.css?v=44" rel="stylesheet" />
</head>
<body>
    <div class="tops">
        <img src="~/Themes/RongJi/Style/luckybag/imgs/top.jpg" class="top_bg" />
        <div class="card_wrapper">
            <img src="~/Themes/RongJi/Style/luckybag/imgs/card.png" class="card" />
        </div>
        @if (@Model.PromotionCodeInfo != null)
        {
            <span class="mymoney">
                <input type="hidden" id="promotionCode" value="@Model.PromotionCodeInfo.PromotionCode">
                 <input type="hidden" id="orderNumber" value="@Request.QueryString["orderNumber"]">
                <input type="hidden" id="currentUserId" value="@WebClientContext.Current.UserId">
                @Html.Raw(@Model.PromotionCodeInfo.Discount.ToString("N0") + "元")
            </span> 
            <div class="use">
                <a href="javascript:void(0);" id="receivePromotionCode" style="margin-top: -10px;">立即领取</a>
            </div>
        }
    </div>

    <div class="fellows">
        <span class="sharetitle" style="margin-top: 10px;">
            @if (@Model.PromotionCodeInfo != null)
            {
                    <p>描述：@Model.PromotionCodeInfo.Description</p>
                    if (@Model.PromotionCodeInfo.PromotionCodeItemList != null && @Model.PromotionCodeInfo.PromotionCodeItemList.Count > 0)
                    {
                        foreach (var item in @Model.PromotionCodeInfo.PromotionCodeItemList)
                        {
                            if (!string.IsNullOrEmpty(@item.ProductId) && @item.UsableType == 1)
                            { 
                                 <p>适用范围 商品限制：item.ProductName</p>
                            }
                            else if ((@item.ManufactoryId != null && @item.ManufactoryId != 0) && (@item.CategoryId != null && @item.CategoryId != 0) && @item.UsableType == 2)
                            {
                                <p>适用范围 品牌+类别限制：@item.ManufactoryName@Html.Raw("品牌-") @item.CategoryName@Html.Raw("类")</p>
                            }
                            else if ((@item.CategoryId != null && @item.CategoryId != 0) && (@item.ManufactoryId == null || @item.ManufactoryId == 0) && @item.UsableType == 4)
                            {
                                <p>适用范围 类别限制： @item.CategoryName@Html.Raw("类")</p>
                            }
                            else if ((@item.ManufactoryId != null && @item.ManufactoryId != 0) && (@item.CategoryId == null || @item.CategoryId == 0) && @item.UsableType == 3)
                            {
                                <p>适用范围 品牌限制： @item.ManufactoryName</p>
                            }
                        }
                    }
                    else
                    {
                        <p>适用范围：全站通用</p>
                    }

                if ((int)@Model.PromotionCodeInfo.LimitAmountType == 0)
                {
                     <p>消费金额限制：@Model.PromotionCodeInfo.Amount.ToString("N2")</p>
                }
                else
                { 
                    <p>消费金额限制：无</p>
                }
                <p>有效日期：@Html.Raw("截止") @Model.PromotionCodeInfo.EndTime</p>
            }
        </span>
    </div>
    <div class="sendTips" onclick="hideShare()"></div>


    <script src="~/Themes/RongJi/Style/base/js/jquery-1.10.1.min.js"></script>
    <script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script>
        $(function () {
            //领取优惠券
            $("#receivePromotionCode").click(function () {
                var orderNumber = $.trim($("#orderNumber").val());
                var promotionCode = $.trim($("#promotionCode").val());
                var currentUserId = $.trim($("#currentUserId").val());
                if (currentUserId <= 0) {
                    var returnUrl = "~/Promotion/PromotionCodeView?promotionCode=" + promotionCode;
                    window.location.href = "../Customer/Login?ReturnUrl=" + returnUrl;
                    return false;
                }
                var submitData = {
                    PromotionCode: promotionCode,
                    orderNumber: orderNumber
                };

                $.ajax({
                    type: "POST",
                    data: submitData,
                    dataType: "JSON",
                    url: "/Promotion/ReceivePrmotionCode",
                    success: function (response) {
                        if (response.Status == false && response.ErrorMessage == 'noHasPromotionCode') {
                            alert('没有优惠码！');
                            return false;
                        }
                        else if (response.Status == true && response.ErrorMessage == 'receiveSuccessfully') {
                            alert('领取成功！');
                            window.location.href = "/myaccount/mypromotioncode?promotiontype=" + response.Tag;
                            return true;
                        }
                        else {
                            alert(response.ErrorMessage);
                            window.location.href = "/myaccount/mypromotioncode?promotiontype=" + response.Tag;
                            return false;
                        }
                    },
                    error: function (err) {
                        //alert('异常错误！');
                        return false;
                    }
                });
            });

            var postData = {
                "currentUrl": window.location.href.replace(window.location.hash, '')
            }
            $.post("http://m.rongji365.com/WeixinJsSdk/ConfigScriptJson", postData, function (wxConfig) {

                wx.config(wxConfig);

                wx.ready(function () {
                    // config信息验证后会执行ready方法，所有接口调用都必须在config接口获得结果之后，config是一个客户端的异步操作，所以如果需要在页面加载时就调用相关接口，则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口，则可以直接调用，不需要放在ready函数中。
                    var config = window.config;
                    wx.onMenuShareAppMessage(config);
                    wx.onMenuShareTimeline(config);
                    wx.onMenuShareQQ(config);
                    wx.onMenuShareWeibo(config);

                    wx.showOptionMenu();
                });

                wx.error(function (res) {

                    // config信息验证失败会执行error函数，如签名过期导致验证失败，具体错误信息可以打开config的debug模式查看，也可以在返回的res参数中查看，对于SPA可以在这里更新签名。

                });
            });
        });
    </script>

    <script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script>
        function onBridgeReady() {
            WeixinJSBridge.call('hideOptionMenu');
        }

        if (typeof WeixinJSBridge == "undefined") {
            if (document.addEventListener) {
                document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
            } else if (document.attachEvent) {
                document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
            }
        } else {
            onBridgeReady();
        }

        $(function () {
            var postData = {
                "currentUrl": location.href.split('#')[0]
            }
            $.post("/WeixinJsSdk/ConfigScriptJson", postData, function (wxConfig) {

                // wxConfig.debug = true;
                wxConfig.jsApiList.push("hideOptionMenu");
                wx.config(wxConfig);

                wx.ready(function () {
                    wx.hideOptionMenu();
                });

                wx.error(function (res) {

                    // config信息验证失败会执行error函数，如签名过期导致验证失败，具体错误信息可以打开config的debug模式查看，也可以在返回的res参数中查看，对于SPA可以在这里更新签名。

                });
            });
        });
    </script>

    <script type="text/javascript" src="http://js.tongji.linezing.com/3547905/tongji.js"></script>
</body>
</html>
